<?php
class PNHouseNoArray extends PNObjectExArray {
  function PNHouseNoArray($init=null, $where='')
  {
    $this->PNObject();

    $this->_objType       = 'votepetition_house_no';
    $this->_objField      = 'id';
    $this->_objPath       = 'form';

    $this->_objJoin[]     = array ( 'join_table'  =>  'votepetition_province',
                            'join_field'          =>  array('name'),
                            'object_field_name'   =>  array('pro_name'),
                            'compare_field_table' =>  'pro_id',
                            'compare_field_join'  =>  'id');

    $this->_objJoin[]     = array ( 'join_table'  =>  'votepetition_district',
                            'join_field'          =>  array('name'),
                            'object_field_name'   =>  array('dis_name'),
                            'compare_field_table' =>  'dis_id',
                            'compare_field_join'  =>  'id');

    $this->_objJoin[]     = array ( 'join_table'  =>  'votepetition_tambon',
                            'join_field'          =>  array('name'),
                            'object_field_name'   =>  array('tam_name'),
                            'compare_field_table' =>  'tam_id',
                            'compare_field_join'  =>  'id');

    $this->_objJoin[]     = array ( 'join_table'  =>  'votepetition_village',
                            'join_field'          =>  array('name'),
                            'object_field_name'   =>  array('vil_name'),
                            'compare_field_table' =>  'vil_id',
                            'compare_field_join'  =>  'id');

    $this->_init($init, $where);
  }

  function genSort(){
    //return " ";
    return " ORDER BY pro_name, dis_name, tam_name, vil_id, hou_no ASC";
  }

  function genFilter(){
    $form  = FormUtil::getPassedValue ('form', false);
    $wheres = array();
    if ($form['pro_id'] && intval($form['pro_id'])) $wheres[] = " hou_pro_id = ".$form['pro_id'];
    if ($form['dis_id'] && intval($form['dis_id'])) $wheres[] = " hou_dis_id = ".$form['dis_id'];
    if ($form['tam_id'] && intval($form['tam_id'])) $wheres[] = " hou_tam_id = ".$form['tam_id'];
    if ($form['vil_id'] && intval($form['vil_id'])) $wheres[] = " hou_vil_id = ".$form['vil_id'];

    if($wheres){
      return implode(' AND ', $wheres) ;
    }else{
      return " ";
    }
  }
}
